package com.smart.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smart.common.core.domain.R;
import com.smart.common.core.page.PageQuery;
import com.smart.system.domain.Car;
import com.smart.system.domain.Employee;
import com.smart.system.domain.dto.BoundCarDto;
import com.smart.system.domain.dto.BoundEmployeeDto;
import com.smart.system.domain.vo.AreaVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.enums.BusinessType;
import com.smart.system.domain.Area;
import com.smart.system.service.IAreaService;

import java.util.List;

/**
 * 区域Controller
 * 
 * @author smart
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/system/area")
@Api(tags = "区域")
public class AreaController extends BaseController
{
    @Autowired
    private IAreaService areaService;

    /**
     * 查询区域列表
     */
    @ApiOperation(value = "查询区域列表")
    //@PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/list")
    public R<IPage<AreaVo>> list(String content, PageQuery pageQuery)
    {
        return R.ok(areaService.selectAreaList(content,pageQuery.toPage()));
    }

    /**
     * 获取区域详细信息
     */
    @ApiOperation(value = "获取区域详细信息")
    //@PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{id}")
    public R<Area> getInfo(@PathVariable("id") Integer id)
    {
        return R.ok(areaService.selectAreaById(id));
    }

    /**
     * 新增区域
     */
    @ApiOperation(value = "新增区域")
    //@PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "区域", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Integer> add(@RequestBody Area area)
    {
        return R.ok(areaService.insertArea(area));
    }

    /**
     * 修改区域
     */
    @ApiOperation(value = "修改区域")
    //@PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Integer> edit(@RequestBody Area area)
    {
        return R.ok(areaService.updateArea(area));
    }

    /**
     * 删除区域
     */
    @ApiOperation(value = "删除区域")
    //@PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<Integer> remove(@PathVariable Integer[] ids)
    {
        return R.ok(areaService.deleteAreaByIds(ids));
    }

    @ApiOperation(value = "区域绑定员工-绑定")
    //@PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "区域", businessType = BusinessType.DELETE)
    @PostMapping("/boundEmployees")
    public R<Boolean> boundEmployees(@RequestBody BoundEmployeeDto dto)
    {
        return R.ok(areaService.boundEmployee(dto));
    }

    @ApiOperation(value = "区域绑定员工-解绑")
    //@PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "区域", businessType = BusinessType.DELETE)
    @PostMapping("/unboundEmployees")
    public R<Boolean> unboundEmployees(@RequestBody BoundEmployeeDto dto)
    {
        return R.ok(areaService.unBoundEmployee(dto));
    }

    @ApiOperation(value = "区域绑定员工-列表")
    //@PreAuthorize("@ss.hasPermi('system:area:list')")
    @Log(title = "区域", businessType = BusinessType.DELETE)
    @PostMapping("/listEmployees")
    public R<IPage<Employee>> listEmployee(Integer areaId,String name, PageQuery pageQuery)
    {
        return R.ok(areaService.listEmployee(areaId,name,pageQuery));
    }

    @ApiOperation(value = "区域绑定员工-ids")
    //@PreAuthorize("@ss.hasPermi('system:area:list')")
    @Log(title = "区域", businessType = BusinessType.DELETE)
    @PostMapping("/listEmployeeIds")
    public R<List<Integer>> listEmployeeIds(Integer areaId)
    {
        return R.ok(areaService.listEmployeeIds(areaId));
    }


    @ApiOperation(value = "区域绑定车辆-绑定")
    //@PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "区域", businessType = BusinessType.UPDATE)
    @PostMapping("/boundCars")
    public R<Boolean> boundCars(@RequestBody BoundCarDto dto)
    {
        return R.ok(areaService.boundCars(dto));
    }

    @ApiOperation(value = "区域绑定车辆-解绑")
    //@PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "区域", businessType = BusinessType.UPDATE)
    @PostMapping("/unboundCars")
    public R<Boolean> unboundCars(@RequestBody BoundCarDto dto)
    {
        return R.ok(areaService.unBoundCars(dto));
    }

    @ApiOperation(value = "区域绑定车辆-列表")
    //@PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "区域", businessType = BusinessType.UPDATE)
    @PostMapping("/listCars")
    public R<IPage<Car>> listCars(Integer areaId,String content,PageQuery pageQuery)
    {
        return R.ok(areaService.listCars(areaId,content,pageQuery));
    }


    @ApiOperation(value = "区域绑定车辆-ids")
    //@PreAuthorize("@ss.hasPermi('system:area:edit')")
    @PostMapping("/listCarsIds")
    public R<List<Integer>> listCarsIds(Integer areaId)
    {
        return R.ok(areaService.listCarsIds(areaId));
    }

}
